package com.lgz.dbcourse.util;

import com.lgz.dbcourse.dto.ResultSet;
import ma.glasnost.orika.impl.DefaultMapperFactory;

/**
 * @Author: LGZ
 * @Date: 2021/4/10 15:57
 * @Description:
 */
public class CommonUtil {

    public static ResultSet resultReturn(Object data) {
        return new ResultSet(data, 200, "操作成功");
    }

    public static ResultSet resultReturn(Object data, int code, String msg) {
        return new ResultSet(data, code, msg);
    }

    public static DefaultMapperFactory getMapperFactory() {
        return new DefaultMapperFactory.Builder().build();
    }

    /**
     * 字符串的右对齐输出
     * @param c 填充字符
     * @param l 填充后字符串的总长度
     * @param string 要格式化的字符串
     */
    public static String flushRight(char c, long l, String string)
    {
        String str;
        StringBuilder temp = new StringBuilder();
        if (string.length() > l) {
            str = string;
        } else {
            for (int i = 0; i < l - string.length(); i++) {
                temp.append(c);
            }
        }
        str = temp + string;
        return str;
    }
    /**
     * 字符串的左对齐输出
     * @param c 填充字符
     * @param l 填充后字符串的总长度
     * @param string 要格式化的字符串
     */
    public static String flushLeft(char c, long l, String string)
    {
        String str;
        StringBuilder temp = new StringBuilder();
        if (string.length() > l) {
            str = string;
        } else {
            for (int i = 0; i < l - string.length(); i++) {
                temp.append(c);
            }
        }
        str = string+temp;
        return str;
    }
}
